<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
</head>

<body>
    <div class="nav">
        <img src="image/log.jpg" alt="">
        <span class="title">我的博客系统</span>
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="user/logout">注销</a>
    </div>
    <!-- 这里的 .container 作为页面的版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="left">
            <!-- 表示整个用户信息区域. -->
            <div class="card">
                <img src="image/head.jpg" alt="">
                <h3></h3>
                <a href="#">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="right">
            <!-- .blog 就对应一个博客
            <div class="blog">
                博客标题
                <div class="title">
                    我的第一篇博客
                </div>
                博客发布时间
                <div class="date">
                    2023-03-25 20:52:00
                </div>
                博客的摘要
                <div class="desc">
                    从今天起, 我要认真敲代码. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla alias tenetur ut velit ex voluptatibus consequatur quam exercitationem, assumenda ea blanditiis repudiandae? Repellendus tenetur nostrum asperiores molestias doloremque cupiditate maiores.
                </div>
                <a href="blog_detail.html">查看全文 &gt;&gt; </a>
            </div> -->
            <!-- <div class="blog"> -->
            <!-- 博客标题
                <div class="title">
                    我的第二篇博客
                </div>
                博客发布时间
                <div class="date">
                    2023-03-26 20:52:00
                </div>
                博客的摘要
                <div class="desc">
                    从今天起, 我要认真敲代码. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla alias tenetur ut velit ex voluptatibus consequatur quam exercitationem, assumenda ea blanditiis repudiandae? Repellendus tenetur nostrum asperiores molestias doloremque cupiditate maiores.
                </div>
                <a href="blog_detail.html">查看全文 &gt;&gt; </a> -->
            <!-- </div> -->
        </div>
    </div>
    </div>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/commom.js"></script>
    <script>
        //在页面加载的时候通过ajax给服务器发送数据,获取到博客列表信息,并且显示在界面上
        function getBloglist() {
            $.ajax({
                type: 'get',
                url: '/blog/load',
                success: function (body) {
                    //拿到右框框,然后清空,从服务器拿数据
                    let righrDiv = document.querySelector('.right')
                    righrDiv.innerHTML = '';
                    //遍历body,构造出一个一个的 blogDiv
                    for (let blog of body) {
                        let blogDiv = document.createElement('div');
                        blogDiv.className = 'blog';
                        //构造标题
                        let titleDiv = document.createElement('div');
                        titleDiv.className = 'title';
                        titleDiv.innerHTML = blog.title;
                        blogDiv.appendChild(titleDiv);
                        //构造发布时间
                        let dateDiv = document.createElement('div');
                        dateDiv.className = 'date';
                        dateDiv.innerHTML = blog.postTime;
                        blogDiv.appendChild(dateDiv);
                        //构造摘要
                        let descDiv = document.createElement('div');
                        descDiv.className = 'desc';
                        descDiv.innerHTML = blog.content;
                        blogDiv.appendChild(descDiv);
                        //构造a标签
                        let a = document.createElement('a')
                        a.innerHTML = '查看全文 &gt;&gt';
                        //希望跳转的到指定详情页
                        a.href = 'blog_detail.html?blogId=' + blog.blogId;
                        blogDiv.appendChild(a);

                        //把blogDiv 挂到dom树上
                        righrDiv.appendChild(blogDiv);
                    }
                },
                error: function () {
                    alert('获取博客列表失败!');
                }
            });
        }
        getBloglist()

        //用于检验当前状态是否是登陆
        getUserInfo("blog_list.html")
    </script>
</body>

</html>